package com.example.test.dialogfactory;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import easier.calendar.CalendarUtils;
import easier.calendar.CalendarView;
import easier.calendar.CalendarView.CalendarAdapter;
import java.util.Date;

public class MainActivity96 extends AppCompatActivity {

    private CalendarView mCalendar;

    public static void start( Context context ) {

        Intent starter = new Intent( context, MainActivity96.class );
        context.startActivity( starter );
    }

    @Override
    protected void onCreate( Bundle savedInstanceState ) {

        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main96 );
        initView();
    }

    private void initView() {

        mCalendar = (CalendarView) findViewById( R.id.calendar );
        mCalendar.setCalendarAdapter( new CalendarAdapter() {

            @Override
            public View onCreateView( @NonNull ViewGroup parent, int viewType ) {

                return LayoutInflater.from( parent.getContext() ).inflate( R.layout.activity_main96_item, parent, false );
            }

            @Override
            public void onBindView( @NonNull View view, Date current, int position ) {

                int year = CalendarUtils.getYear( current );
                int month = CalendarUtils.getMonth( current );
                int dayOfMonth = CalendarUtils.getDayOfMonth( current );

                ((TextView) view.findViewById( R.id.text )).setText( String.valueOf( year ) );
                ((TextView) view.findViewById( R.id.text0 )).setText( String.valueOf( month ) );
                ((TextView) view.findViewById( R.id.text1 )).setText( String.valueOf( dayOfMonth ) );
            }
        } );
    }
}